// user.entity.ts
import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToMany,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Role } from '@/role/entities/role.entity';
import { TestingMachine } from '@/testing-machine/entities/testing-machine.entity';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  userName: string;

  @Column({
    type: 'json',
  })
  // 虫体英文名
  speciesName: any = [];

  @Column()
  password: string;

  @Column({
    default: '林业单位',
  })
  desc: string;

  @Column()
  companyLabel: string;

  @Column()
  companyType: string;

  @Column({
    default: 0,
  })
  companyParent: number;

  @CreateDateColumn({
    type: 'datetime',
    default: null,
  })
  createTime: Date = new Date();

  @UpdateDateColumn({
    type: 'datetime',
    default: null,
  })
  updateTime: Date = new Date();

  @ManyToMany(() => Role, (role) => role.users, { cascade: true })
  roles: Role[];

  @OneToMany(() => TestingMachine, (machine) => machine.user, { cascade: true })
  testingMachines: TestingMachine[];
}
